//
//  UIViewController+Init.m
//  ReplyAssistant
//
//  Created by Leo on 2018/11/24.
//  Copyright © 2018 KK. All rights reserved.
//

#import "UIViewController+Helper.h"

@implementation UIViewController (Init)

+ (instancetype)viewControllerFromSB {
    return [self viewControllerFromSB: @"Main" identifier: NSStringFromClass([self class])];
}

+ (instancetype)viewControllerFromSB:(NSString*)name {
    return [self viewControllerFromSB: name identifier: NSStringFromClass([self class])];
}

+ (instancetype)viewControllerFromSB:(NSString *)name identifier:(NSString*)identifier {
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName: name == nil ? @"Main" : name bundle: [NSBundle mainBundle]];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier: identifier == nil ? NSStringFromClass([self class]) : identifier];
    
    return viewController;
}
@end

@implementation UIViewController (NavigationItem)

//  设置右边导航栏item的事件
- (void)setRightBarButtonItemWithTitle:(NSString*)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle: title style: style target: target action: action];
//    CDD3DC
    item.tintColor = [UIColor colorWithHexString: @"8190A7"];
    self.navigationItem.rightBarButtonItem = item;
}

- (void)setRightBarButtonItemWithImageName:(NSString*)imageName style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: imageName] style:style target: target action:action];
    item.tintColor = [UIColor colorWithHexString: @"8190A7"];
    self.navigationItem.rightBarButtonItem = item;
}

//  设置左边导航栏item的事件
- (void)setLeftBarButtonItemWithTitle:(NSString*)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle: title style: style target: target action: action];
    item.tintColor = [UIColor colorWithHexString: @"8190A7"];
    self.navigationItem.leftBarButtonItem = item;
}

- (void)setLeftBarButtonItemWithImageName:(NSString*)imageName style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: imageName] style:style target: target action:action];
    item.tintColor = [UIColor colorWithHexString: @"8190A7"];
    self.navigationItem.leftBarButtonItem = item;
}

@end
